import axios from "@/util/http";
import { useStore } from "vuex";

export default {
  state: {
    food_list: [],
    producible_food_list: [],
  },
  getters: {},
  mutations: {},
  actions: {
    get_all_producible_food(context, data) {
      const url = "/food/get/all/producible/";
      console.log(useStore().state.user.jwt_token);
      const config = {
        headers: {
          Authorization: "Bearer " + useStore().state.user.jwt_token,
        },
      };
      axios
        .post(url, data, config)
        .then((resp) => {
          console.log(resp.data);
          context.state.producible_food_list = resp.data;
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
    get_all_food(context, data) {
      const url = "/food/get/all/";
      const config = {
        headers: {
          Authorization: "Bearer " + useStore().state.user.jwt_token,
        },
      };
      axios.post(url, data, config).then((resp) => {
        context.state.food_list = resp.data.data;
      });
    },
    get_all_food_1(context, data) {
      const url = "/food/get/all/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        context.state.food_list = resp.data.data;
      });
    },
    add_food(context, data) {
      const url = "/food/add/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        data.success(resp.data);
      });
    },
    delete_food(context, data) {
      const url = "/food/delete/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        data.success(resp.data);
      });
    },
    modify_food(context, data) {
      const url = "/food/modify/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        data.success(resp.data);
      });
    },
  },
  modules: {},
};
